package com.kayb.patterns.creational;

/**
 * 工厂方法
 * 缺点：每次新增工厂类需要修改工厂方法`create`，破坏开闭原则
 * @author huangkaibin
 * @date 2018-08-28
 **/
public class FactoryMethod {

    public interface NameService {
        void intro();
    }

    protected static class Lyly implements NameService {
        @Override
        public void intro() {
            System.out.println("i'm lyly");
        }
    }

    protected static class Alex implements NameService {
        @Override
        public void intro() {
            System.out.println("i'm Alex");
        }
    }

    static NameService create(String name) {
        if ("Alex".equals(name)) {
            return new Alex();
        }
        return new Lyly();
    }

    public static void main(String[] args) {
        NameService name = create("Alex");
        name.intro();
    }

}
